package com.drug.controller;

import com.drug.domain.Hospital;
import com.drug.domain.Result;
import com.drug.domain.SupervisoryBody;
import com.drug.mapper.SupervisoryBodyMapper;
import com.drug.mapper.SupplierMapper;
import com.drug.service.SupervisoryBodyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEventHttpMessageReader;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.rmi.ServerError;
import java.util.List;

@RestController
public class SupervisoryBodyController {
    @Autowired
    private SupervisoryBodyService supervisoryBodyService;
    @Autowired
    private SupervisoryBodyMapper supervisoryBodyMapper;

    //多条件查询监督机构
    @ResponseBody
    @RequestMapping("/selectSupervisoryBody")
    public List<SupervisoryBody> selectHospital(SupervisoryBody supervisoryBody) {
        List<SupervisoryBody> supervisoryBodyList = supervisoryBodyService.selectSupervisoryBody(supervisoryBody);
        return supervisoryBodyList;
    }

    //分页查询
    @RequestMapping("/selectSupervisoryBodyAll")
    @ResponseBody
    public Result pageSupervisoryFindAll(@RequestParam(required=true,defaultValue="1")Integer pageNum){
        return supervisoryBodyService.pageSupervisoryFindAll(pageNum);
    }

    //逻辑删除
    @ResponseBody
    @RequestMapping("/deleteSupervisoryBody")
    public String deleteHospital(Integer sbId){
        supervisoryBodyService.deleteSupervisoryBody(sbId);
        return "drug supervisorybody";
    }


    //添加医院
    @ResponseBody
    @RequestMapping("/insertSupervisoryBody")
    public void insertSupervisoryBody(SupervisoryBody supervisoryBody){
        supervisoryBodyService.insertSupervisoryBody(supervisoryBody);
    }

    //查询
    @ResponseBody
    @RequestMapping("/selectsbById")
    public SupervisoryBody selectById(String supId){
        SupervisoryBody supervisoryBody = supervisoryBodyMapper.selectsbById(Integer.valueOf(supId));
        System.err.println(supervisoryBody);
        return  supervisoryBody;
    }

    //修改医院
    @ResponseBody
    @RequestMapping("/updateSupervisoryBody")
    public List<SupervisoryBody> updateSupervisoryBody(SupervisoryBody supervisoryBody){
        System.err.println(supervisoryBody);
        return supervisoryBodyService.updateSupervisoryBody(supervisoryBody);

    }
    @ResponseBody
    @RequestMapping("/findSupervisoryname")
    public Result selectSupervisoryname(String sbname){
         return supervisoryBodyService.selectSupervisoryname(sbname);
    }
}